<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>电脑商城</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		<script src="../bootstrap3/js/holder.js"></script>
		<link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
		<script src="../bootstrap3/js/bootstrap.js"></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="../css/layout.css" />
		<link rel="stylesheet" type="text/css" href="../css/top.css" />
		<link rel="stylesheet" type="text/css" href="../css/footer.css" />
		<link rel="shortcut icon" href="../favicon.ico"/>
	</head>

	<body>
		<div class="container">
			<div class="col-md-10">
				<div class="panel panel-default">
					<ul class="nav nav-tabs">
						<li ><a href="index.html">我的文件</a></li>
						<li><a href="myshare.html">我的共享</a></li>
						<li><a href="share.html">别人共享</a></li>
						<li class="active"><a href="password.html">修改密码</a></li>
						<li> <a href="login.html" onclick="logout()">注销登录</a></li>
					</ul>
					<div class="panel-body">
						<!--修改密码表单开始-->
						<form id="form-change-password" class="form-horizontal" role="form">
							<div class="form-group">
								<label class="col-md-2 control-label">原密码：</label>
								<div class="col-md-8">
									<input name="oldPassword" type="text" class="form-control" placeholder="请输入原密码">
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-2 control-label">新密码：</label>
								<div class="col-md-8">
									<input name="newPassword" type="text" class="form-control" placeholder="请输入新密码">
								</div>
							</div>
							<div class="form-group">
								<label class="col-md-2 control-label">确认密码：</label>
								<div class="col-md-8">
									<input type="text" class="form-control" placeholder="请再次输入新密码">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-10">
									<input id="btn-change-password" type="button" class="btn btn-primary" value="修改" />
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$("#btn-change-password").click(function() {
				$.ajax({
					url: "/login/change_password",
					type: "POST",
					data: $("#form-change-password").serialize(), //自动系列化，&连接的参数值
					dataType: "json",
					success: function(json) {
						if (json.state == 200) {
							alert("密码修改成功！");
						} else {
							alert("密码修改失败！" + json.message);
						}
					},
					//当服务器未正常响应状态码时，例如出现302、400、404、405、500等状态码时，将会调用该函数。
					error: function (xhr) {
						alert("修改密码返回异常" + xhr.status);
						//location.href = "login.html";
					}
				});
			});

			function logout(){
				$.ajax({
					url: "/login/logout",
					type: "POST",
					data: new FormData($("#form-change-avatar")[0]),
					dataType: "JSON",
					processData: false, // 关闭processData处理数据
					contentType: false, // 关闭contentType发送数据的格式
					success: function(json) {
						if (json.state == 200) {
							location.href = "login.html";
						} else {
							alert("失败！" + json.message);
						}
					},
					error: function(xhr) {
						alert("返回异常" + xhr.status);
					}
				});
			}
		</script>
	</body>

</html>